package com.avic.rong.adapter.show;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.avic.rong.R;
import com.avic.rong.activity.VideoDetailActivity;
import com.avic.rong.bean.show_bean.AnLiBean;
import com.avic.rong.bean.show_bean.EsInfoBean;
import com.avic.rong.utils.GlideUtils;
import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 关注
 * Creater: Created by wangyz on 2017/1/10.
 * Email: 936804097@qq.com
 */

public class AnLiHAdapter extends RecyclerView.Adapter<AnLiHAdapter.RecommendViewHolder> {

    private Context mContext;
    private List<AnLiBean.DataBean> data;
    private ArrayList<EsInfoBean> esInfoBeans;

    public AnLiHAdapter(Context mContext) {
        this.mContext = mContext;

    }

    public void setBean(List<AnLiBean.DataBean> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    public void setEsInfoBeans(ArrayList<EsInfoBean> esInfoBeans) {
        this.esInfoBeans = esInfoBeans;
        notifyDataSetChanged();
    }

    @Override
    public AnLiHAdapter.RecommendViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.anli_item, parent, false);
        return new RecommendViewHolder(view);
    }

    @Override
    public void onBindViewHolder(AnLiHAdapter.RecommendViewHolder holder, int position) {
        if (esInfoBeans != null && esInfoBeans.size() > 0) {
            holder.anli_biao.setText(esInfoBeans.get(position).getAuthor());

            GlideUtils.loaderGlideCircleImage(mContext,esInfoBeans.get(position).getLogo(),holder.logo);


            holder.anli_readsize.setText(esInfoBeans.get(position).getView_num() + "阅读");

        }
        if (data != null && data.size() > 0) {



            holder.anli_title.setText(data.get(position).getTitle());
            Glide.with(mContext).load(data.get(position).getImg()).error(R.mipmap.doc_default)
                    .placeholder(R.mipmap.doc_default)
                    .into(holder.anli_img);



            String postTime = data.get(position).getPostTime();
            holder.anli_before.setText(postTime);
        }



        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, VideoDetailActivity.class);
                int contId = data.get(position).getDataId();
                intent.putExtra("contId", contId);
                mContext.startActivity(intent);
            }
        });
    }


    @Override
    public int getItemCount() {
        return esInfoBeans == null ? 0 : esInfoBeans.size();
    }




    class RecommendViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.anli_before)
        TextView anli_before;
        @BindView(R.id.anli_biao)
        TextView anli_biao;
        @BindView(R.id.anli_img)
        ImageView anli_img;
        @BindView(R.id.logo)
        ImageView logo;
        @BindView(R.id.anli_readsize)
        TextView anli_readsize;
        @BindView(R.id.anli_title)
        TextView anli_title;

        public RecommendViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);

        }
    }
}
